<template>
  <li :class="{ completed: task.completed }">
    <input type="checkbox" v-model="task.completed" />
    <span>{{ task.text }}</span>
    <button @click="deleteTask">删除</button>
  </li>
</template>

<script setup>
import { defineProps, defineEmits } from 'vue';

const props = defineProps({
  task: {
    type: Object,
    required: true
  }
});

const emits = defineEmits(['delete']);

const deleteTask = () => {
  emits('delete', props.task.id);
};
</script>

<style scoped>
li {
  display: flex;
  align-items: center;
  padding: 10px;
  margin-bottom: 10px;
  background-color: #f9f9f9;
  border-radius: 4px;
}

.completed span {
  text-decoration: line-through;
  color: #888;
}

input[type="checkbox"] {
  margin-right: 10px;
}

button {
  margin-left: auto;
  padding: 5px 10px;
  background-color: #e74c3c;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

button:hover {
  background-color: #c0392b;
}
</style>